﻿Imports System.Data.SqlClient

Public Class FormStoreEditor


    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        If txtStoreId.Text = "" Then
            Dim cn As New SqlConnection()
            cn.ConnectionString = "server=.;uid=sa;pwd=123;database=SaleDb;"
            cn.Open()

            Dim cmd As New SqlCommand()
            cmd.Connection = cn
            cmd.CommandText = "INSERT INTO Store VALUES(N'" & txtStoreName.Text & "',1)"
            cmd.ExecuteNonQuery()
        Else
            Dim cn As New SqlConnection()
            cn.ConnectionString = "server=.;uid=sa;pwd=123;database=SaleDb;"
            cn.Open()

            Dim cmd As New SqlCommand()
            cmd.Connection = cn
            cmd.CommandText = "UPDATE Store SET StoreName =N'" & txtStoreName.Text & "' WHERE StoreId=" & txtStoreId.Text
            cmd.ExecuteNonQuery()
        End If
        Me.DialogResult = Windows.Forms.DialogResult.OK



    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub txtStoreId_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStoreId.TextChanged

    End Sub
End Class